package com.wzq.solution;

class Solution75 {
    public static void sortColors(int[] nums) {
        int l=0;
        int r = nums.length-1;

        int i=0;
        do {
            while(l<=r && nums[l] == 0 ){
                l++;
            }
            while(l<=r && nums[r] == 2){
                r--;
            }
            if(nums[i] == 2 && l<=r){
                nums[i] = nums[r];
                nums[r] = 2;
                r--;
            }else if(nums[i] == 1 && l<=r){
                nums[i] = nums[l];
                nums[l] = 1;
                l++;
            }else{
                i++;
            }

        }while(i<=r);

        return;
    }

    public static void main(String[] args) {
        int[] a = new int[]{2,0,1};
        sortColors(a);
    }
    
}